<!DOCTYPE html>
<html lang="zh-Hans">

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="x5-fullscreen" content="true">
<meta name="full-screen" content="yes">
<meta name="theme-color" content="#317EFB" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=0" name="viewport">
<meta name="description" content="windows设置定时任务 最近在做一个项目，需要同步三方的数据，所以需要使用到windows上的定时任务，特意记录一下。 参考原文地址： https:&#x2F;&#x2F;zhidao.baidu.com&#x2F;question&#x2F;514946528.html 用cmd命令行指定每一分钟运行某程序例子： 1234567891011121314151617181920schtasks &#x2F;create &#x2F;tn koto2k">
<meta property="og:type" content="article">
<meta property="og:title" content="windows设置定时任务">
<meta property="og:url" content="https://gitee.com/yuxiaoxiao.net/blog/2022/04/24/PHP/windows%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1schtasks/index.html">
<meta property="og:site_name" content="技术有限的博客">
<meta property="og:description" content="windows设置定时任务 最近在做一个项目，需要同步三方的数据，所以需要使用到windows上的定时任务，特意记录一下。 参考原文地址： https:&#x2F;&#x2F;zhidao.baidu.com&#x2F;question&#x2F;514946528.html 用cmd命令行指定每一分钟运行某程序例子： 1234567891011121314151617181920schtasks &#x2F;create &#x2F;tn koto2k">
<meta property="og:locale">
<meta property="article:published_time" content="2022-04-24T05:44:29.000Z">
<meta property="article:modified_time" content="2023-02-07T02:30:06.121Z">
<meta property="article:author" content="姑苏城外">
<meta name="twitter:card" content="summary">


<title >windows设置定时任务</title>

<!-- Favicon -->

    <link href='/blog/img/favicon.ico?v=2.0.0' rel='icon' type='image/png' sizes='16x16' ></link>


    <link href='/blog/img/favicon.ico?v=2.0.0' rel='icon' type='image/png' sizes='32x32' ></link>




<!-- Plugin -->




    
<link rel="stylesheet" href="/blog/css/plugins/bootstrap.row.css">

    
<link rel="stylesheet" href="https://unpkg.com/locomotive-scroll@4.1.4/dist/locomotive-scroll.min.css">

    
<link rel="stylesheet" href="https://unpkg.com/@fancyapps/ui@4.0/dist/fancybox.css">

    
    




<!-- Icon -->

    
<link rel="stylesheet" href="/blog/css/plugins/font-awesome.min.css">




<!-- Variable -->
<script>window.ASYNC_CONFIG = {"hostname":"gitee.com","author":"姑苏城外","root":"/blog/","typed_text":["Web Developer"],"theme_version":"2.0.0","theme":{"switch":true,"default":"style-light"},"favicon":{"logo":"/img/jsyx.jpg","icon16":"/img/favicon.ico","icon32":"/img/favicon.ico","appleTouchIcon":null,"webmanifest":null,"visibilitychange":false,"hidden":"/failure.ico","showText":"(/≧▽≦/)咦！又好了！","hideText":"(●—●)喔哟，崩溃啦！"},"i18n":{"placeholder":"搜索...","empty":"找不到您查询的内容: ${query}","hits":"找到 ${hits} 条结果","hits_time":"找到 ${hits} 条结果（用时 ${time} 毫秒）","author":"本文作者：","copyright_link":"本文链接：","copyright_license_title":"版权声明：","copyright_license_content":"本博客所有文章除特别声明外，均默认采用 undefined 许可协议。","copy_success":"复制成功","copy_failure":"复制失败","open_read_mode":"进入阅读模式","exit_read_mode":"退出阅读模式","notice_outdate_message":"距离上次更新已经 undefined 天了, 文章内容可能已经过时。","just":"刚刚","min":"分钟前","hour":"小时前","day":"天前","month":"个月前"},"swup":false,"plugin":{"flickr_justified_gallery":"https://unpkg.com/flickr-justified-gallery@latest/dist/fjGallery.min.js"},"icons":{"sun":"far fa-sun","moon":"far fa-moon","play":"fas fa-play","email":"far fa-envelope","next":"fas fa-arrow-right","calendar":"far fa-calendar-alt","clock":"far fa-clock","user":"far fa-user","back_top":"fas fa-arrow-up","close":"fas fa-times","search":"fas fa-search","reward":"fas fa-hand-holding-usd","user_tag":"fas fa-user-alt","toc_tag":"fas fa-th-list","read":"fas fa-book-reader","arrows":"fas fa-arrows-alt-h","double_arrows":"fas fa-angle-double-down","copy":"fas fa-copy"},"icontype":"font","highlight":{"plugin":"highlighjs","theme":true,"copy":true,"lang":true,"title":"default","height_limit":false}};</script>
<script id="async-page-config">window.PAGE_CONFIG = {"isPost":true,"isHome":false,"postUpdate":"2023-02-07 10:30:06"};</script>

<!-- Theme mode css -->
<link data-swup-theme rel="stylesheet" href="/blog/css/index.css?v=2.0.0" id="trm-switch-style">
<script>
    let defaultMode = ASYNC_CONFIG.theme.default !=='auto' ?  ASYNC_CONFIG.theme.default : (window.matchMedia("(prefers-color-scheme: light)").matches ? 'style-light' : 'style-dark')
    let catchMode = localStorage.getItem('theme-mode') || defaultMode;
    let type = catchMode === 'style-dark' ? 'add' : 'remove';
    document.documentElement.classList[type]('dark')
</script>

<!-- CDN -->


    
    



<!-- Site Analytics -->
 
<meta name="generator" content="Hexo 6.3.0"></head>

<body>

  <!-- app wrapper -->
  <div class="trm-app-frame">

    <!-- page preloader -->
    <div class="trm-preloader">
    <div class="trm-holder">
        <div class="preloader">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>
    <!-- page preloader end -->

    <!-- change mode preloader -->
    <div class="trm-mode-swich-animation-frame">
    <div class="trm-mode-swich-animation">
        <i class="i-sun"><i class="iconfont far fa-sun"></i></i>
        <div class="trm-horizon"></div>
        <i class="i-moon"><i class="iconfont far fa-moon"></i></i>
    </div>
</div>
    <!-- change mode preloader end -->

      <!-- scroll container -->
      <div id="trm-dynamic-content" class="trm-swup-animation">
        <div id="trm-scroll-container" class="trm-scroll-container" data-scroll-container style="opacity: 0">
          <div data-scroll-section id="content" class="trm-scroll-section">

            <div class="locomotive-scroll__sticky-target" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none;"></div>

            <!-- top bar -->
            <header class="trm-top-bar" data-scroll data-scroll-sticky data-scroll-target=".locomotive-scroll__sticky-target" >
	<div class="container">
		<div class="trm-left-side">
			<!-- logo -->
<a href="/blog/" class="trm-logo-frame trm-anima-link">
    
        <img alt="logo" src="/blog/img/jsyx.jpg">
    
    
        <div class="trm-logo-text">
            技术<span>有限</span>
        </div>
    
</a>
<!-- logo end -->
		</div>
		<div class="trm-right-side">
			<!-- menu -->
<div class="trm-menu">
    <nav>
        <ul>
            
            <li class="menu-item-has-children ">
                <a  href="/blog/" target="">
                    首页
                </a>
                
            </li>
            
            <li class="menu-item-has-children ">
                <a  href="/blog/archives/" target="">
                    归档
                </a>
                
            </li>
            
        </ul>
    </nav>
</div>
<!-- menu end -->
			
    <!-- mode switcher place -->
    <div class="trm-mode-switcher-place">
        <div class="trm-mode-switcher">
            <i class="iconfont far fa-sun"></i>
            <input class="tgl tgl-light" id="trm-swich" type="checkbox">
            <label class="trm-swich" for="trm-swich"></label>
            <i class="iconfont far fa-moon"></i>
        </div>
    </div>
    <!-- mode switcher place end -->

			
		</div>
		<div class="trm-menu-btn">
			<span></span>
		</div>
	</div>
</header>
            <!-- top bar end -->

            <!-- body -->
            
<div class="trm-content-start">
    <!-- banner -->
    <div class="trm-banner" data-scroll data-scroll-direction="vertical">
    
    <!-- banner cover -->
    <img style="object-position:top;object-fit:cover;" alt="banner" class="trm-banner-cover" data-scroll data-scroll-direction="vertical" data-scroll-speed="-3" src="/blog/img/banner.png">
    <!-- banner cover end -->
    

    <!-- banner content -->
    <div class="trm-banner-content trm-overlay">
        <div class="container" data-scroll data-scroll-direction="vertical" data-scroll-speed="0">
            <div class="row">
                
                <div class="col-lg-4"></div>
                
                <div class="col-lg-8">

                    <!-- banner title -->
                    <div class="trm-banner-text ">
                        <div class="trm-label trm-mb-20">
                            NEWS LETTER
                        </div>
                        <h1 class="trm-mb-30 trm-hsmb-font">
                            windows设置定时任务
                        </h1>

                        
                            <ul class="trm-breadcrumbs trm-label">
                                <li>
                                    <a href="/blog/" class="trm-anima-link">Home</a>
                                </li>
                                <li>
                                    <span>
                                        2022
                                    </span
                                ></li>
                            </ul>
                        
                    </div>
                    <!-- banner title end -->

                    <!-- scroll hint -->
                    <a href="#about-triger" data-scroll-to="#about-triger" data-scroll-offset="-130" class="trm-scroll-hint-frame">
                        <div class="trm-scroll-hint"></div>
                        <span class="trm-label">Scroll down</span>
                    </a>
                    <!-- scroll hint end -->

                </div>
            </div>
        </div>
    </div>
    <!-- banner content end -->
</div>
    <!-- banner end -->
    <div class="container">
        <div class="row">
            
                <div id="page-sidebar" class="col-lg-4 hidden-sm">
                    <!-- main card -->
                    

<div class="trm-main-card-frame trm-sidebar">
    <div class="trm-main-card" data-scroll data-scroll-sticky data-scroll-target=".locomotive-scroll__sticky-target"> 
    
        <!-- card header -->
<div class="trm-mc-header">
    <div class="trm-avatar-frame trm-mb-20">
        <img alt="Avatar" class="trm-avatar" src="/blog/img/lyy.jpg">
    </div>
    <h5 class="trm-name trm-mb-15">
        姑苏城外
    </h5>
    
        <div class="trm-label">
            I`m
            <span class="trm-typed-text">
                <!-- Words for theme.user.typedText -->
            </span>
        </div>
    
</div>
<!-- card header end -->
        <!-- sidebar social -->

<!-- sidebar social end -->
        <!-- info -->
<div class="trm-divider trm-mb-40 trm-mt-40"></div>
<ul class="trm-table trm-mb-20">
    
        <li>
            <div class="trm-label">
                地址:
            </div>
            <div class="trm-label trm-label-light">
                China
            </div>
        </li>
    
        <li>
            <div class="trm-label">
                年龄:
            </div>
            <div class="trm-label trm-label-light">
                1024
            </div>
        </li>
    
        <li>
            <div class="trm-label">
                性别:
            </div>
            <div class="trm-label trm-label-light">
                男
            </div>
        </li>
    
</ul>
<!-- info end -->

        
    
    </div>
</div>
                    <!-- main card end -->
                </div>
            
            <div id="page-content" class="col-lg-8">
                <div class="trm-content" id="trm-content">
                    <div data-scroll data-scroll-repeat data-scroll-offset="500" id="about-triger"></div>

                    <div id="post-info" class="row hidden-sm">
    <div class="col-sm-4">
        <div class="trm-card trm-label trm-label-light text-center">
            <i class="iconfont far fa-calendar-alt trm-icon"></i><br>
            04/24
        </div>
    </div>
    <div class="col-sm-4">
        <div class="trm-card trm-label trm-label-light text-center">
            <i class="iconfont far fa-clock trm-icon"></i><br>
            13:44
        </div>
    </div>
    <div class="col-sm-4">
        <div id="post-author" class="trm-card trm-label trm-label-light text-center">
            <i class="iconfont far fa-user trm-icon"></i><br>
            姑苏城外
        </div>
    </div>
</div>
<div class="trm-card ">
    <article id="article-container" class="trm-publication">
    <h1><center>windows设置定时任务</center></h1>
<h4 id="最近在做一个项目，需要同步三方的数据，所以需要使用到windows上的定时任务，特意记录一下。">最近在做一个项目，需要同步三方的数据，所以需要使用到windows上的定时任务，特意记录一下。</h4>
<h4 id="参考原文地址：">参考原文地址：</h4>
<p><a target="_blank" rel="noopener" href="https://zhidao.baidu.com/question/514946528.html">https://zhidao.baidu.com/question/514946528.html</a></p>
<p>用cmd命令行指定每一分钟运行某程序例子：</p>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">schtasks /create /tn koto2k /tr C:\windows\system32\notepad.exe /sc minute /mo <span class="number">1</span> /st <span class="number">1</span>:<span class="number">21</span>:<span class="number">00</span> /et <span class="number">2</span>:<span class="number">21</span>:<span class="number">23</span></span><br><span class="line"></span><br><span class="line">解释：</span><br><span class="line"></span><br><span class="line">/create 创建新的计划任务</span><br><span class="line"></span><br><span class="line">/tn 指定任务的名称（例子里任务名称为：koto2k）</span><br><span class="line"></span><br><span class="line">/tr 制定任务运行的程序或命令。键入可执行文件、脚本文件或批处理文件的完全合格的路径和文件名。如果忽略该路径， SchTasks.exe 将假定文件在 Systemroot\System32 目录下。</span><br><span class="line"></span><br><span class="line">/sc 指定计划类型。类型有效值之一(参数)：once 指定任务在指定的日期和时间运行一次。</span><br><span class="line"></span><br><span class="line">/st 以 hh:mm:ss <span class="number">24</span> 小时格式指定时间。默认值是命令完成时的当前本地时间。/st 参数只对于 minute、hourly、daily、weekly、 monthly 和 once 计划有效。它只对于 once 计划是必需的。</span><br><span class="line"></span><br><span class="line">/et 指定任务计划运行的最后日期。此参数是可选的。它对于 ONCE、ONSTART、ONLOGON 或 ONIDLE 计划无效。</span><br><span class="line">默认情况下，计划没有结束日期。</span><br><span class="line"></span><br><span class="line">/sd 以 mm/dd/yyyy 格式指定任务启动的日期。默认值是当前日期。/sd 参数对于所有的计划有效，但只对于 once 计划是必需的。</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="最后实现：">最后实现：</h4>
<figure class="highlight vbs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">//新增定时任务</span><br><span class="line">schtasks /create /tn dianliangzhiku /tr D:\WWW\script.dev.com\bat\dianliangzhiku\run.vbs /sc minute /mo <span class="number">1</span></span><br><span class="line"></span><br><span class="line">//删除定时任务	</span><br><span class="line">schtasks /delete /tn dianliangzhiku</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="这里为什么要使用vbs脚本呢，因为直接调用-bat脚本会显示cmd的黑色窗口，通过vbs调用bat脚本可以解决这个问题，也就是bat脚本处理的是实际的任务-vbs脚本再调用bat的脚本，附vbs脚本代码和bat脚本代码">这里为什么要使用vbs脚本呢，因为直接调用<code>.bat</code>脚本会显示cmd的黑色窗口，通过vbs调用bat脚本可以解决这个问题，也就是bat脚本处理的是实际的任务,vbs脚本再调用bat的脚本，附vbs脚本代码和bat脚本代码</h4>
<h4 id="参考原文地址：-2">参考原文地址：</h4>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/miaojx/p/15690211.html">https://www.cnblogs.com/miaojx/p/15690211.html</a></p>
<h4 id="vbs脚本代码">vbs脚本代码</h4>
<figure class="highlight vbs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">Set</span> ws = <span class="built_in">CreateObject</span>(<span class="string">&quot;Wscript.Shell&quot;</span>)</span><br><span class="line">ws.run <span class="string">&quot;D:\WWW\script.dev.com\bat\dianliangzhiku\run.bat&quot;</span>,<span class="number">0</span></span><br></pre></td></tr></table></figure>
<h4 id="bat脚本代码">bat脚本代码</h4>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"><span class="function">D:\<span class="title">software</span>\<span class="title">phpStudy</span>\<span class="title">php</span>\<span class="title">php</span>-5.6.27-<span class="title">nts</span>\<span class="title">php.exe</span> -<span class="title">q</span> <span class="title">D</span>:\<span class="title">WWW</span>\<span class="title">script.dev.com</span>\<span class="title">bat</span>\<span class="title">dianliangzhiku</span>\<span class="title">run.php</span></span></span><br></pre></td></tr></table></figure>

</article>
    
    
</div>
<div id="post-next-prev" class="row">
    <div class="col-lg-12">
        <!-- title -->
        <h5 class="trm-title-with-divider">
            其他文章
            <span data-number="02"></span>
        </h5>
    </div>
    
        <div class="col-lg-6">
    <div class="trm-blog-card trm-scroll-animation" data-scroll data-scroll-offset="40">
        <a href="/blog/2022/06/01/%E5%89%8D%E7%AB%AF/iOS%20js%20%E8%B0%83%E7%94%A8new%20Date%20%E8%BF%94%E5%9B%9ENaN/" class="trm-cover-frame trm-anima-link">
            
            
                <img alt="cover" class="no-fancybox" src="/blog/img/block.jpg">
            
        </a>
        
        <div class="trm-card-descr">
            <div class="trm-label trm-category trm-mb-20">
                <a href=" /blog/categories/%E5%89%8D%E7%AB%AF/">
                    前端
                </a>
            </div>
            <h5>
                <a href="/blog/2022/06/01/%E5%89%8D%E7%AB%AF/iOS%20js%20%E8%B0%83%E7%94%A8new%20Date%20%E8%BF%94%E5%9B%9ENaN/" class="trm-anima-link">
                    iOS设备js 调用new Date返回NaN问题
                </a>
            </h5>
            <div class="trm-divider trm-mb-20 trm-mt-20"></div>
            <ul class="trm-card-data trm-label">
                <li>22/06/01</li>
                <li>01:29</li>
                
                
            </ul>
        </div>
    </div>
</div>
    
    
        <div class="col-lg-6">
    <div class="trm-blog-card trm-scroll-animation" data-scroll data-scroll-offset="40">
        <a href="/blog/2022/04/05/%E5%89%8D%E7%AB%AF/%E6%89%8B%E6%9C%BA%E5%8F%B7%E6%AD%A3%E5%88%99/" class="trm-cover-frame trm-anima-link">
            
            
                <img alt="cover" class="no-fancybox" src="/blog/img/block.jpg">
            
        </a>
        
        <div class="trm-card-descr">
            <div class="trm-label trm-category trm-mb-20">
                <a href=" /blog/categories/%E5%89%8D%E7%AB%AF/">
                    前端
                </a>
            </div>
            <h5>
                <a href="/blog/2022/04/05/%E5%89%8D%E7%AB%AF/%E6%89%8B%E6%9C%BA%E5%8F%B7%E6%AD%A3%E5%88%99/" class="trm-anima-link">
                    手机号正则表达式
                </a>
            </h5>
            <div class="trm-divider trm-mb-20 trm-mt-20"></div>
            <ul class="trm-card-data trm-label">
                <li>22/04/05</li>
                <li>13:37</li>
                
                
            </ul>
        </div>
    </div>
</div>
    
</div>

    



                    <div class="trm-divider footer-divider"></div>

                    <!-- footer -->
                    <footer class="trm-scroll-animation" data-scroll data-scroll-offset="50">

    

    

    
        <div class="trm-footer-item">
            <span>
                由 <a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a> 驱动 v6.3.0
            </span>
            <span class="footer-separator" data-separator=" | "></span>
            <span> 
                主题 - 
                <a rel="noopener" href='https://github.com/MaLuns/hexo-theme-async' target='_blank'>Async</a>
                v2.0.0
            </span>
        </div>
      

     

     
</footer>
 
                    <!-- footer end -->

                </div>
            </div>
        </div>
    </div>
</div>
            <!-- body end -->

            <div class="trm-fixed-container" data-scroll data-scroll-sticky data-scroll-target=".locomotive-scroll__sticky-target" data-scroll-offset="-10">
    
        <div class="trm-fixed-btn" data-title="阅读模式" onclick="asyncFun.switchReadMode()">
            <i class="iconfont fas fa-book-reader"></i>
        </div>
    
    
</div>
          </div>
        </div>
      </div>
      <!-- scroll container end -->

  </div>
  <!-- app wrapper end -->

  <div id="trm-back-top" class="trm-back-top" data-title="回到顶部">
    <i class="iconfont fas fa-arrow-up"></i>
</div>
  
  <!-- Plugin -->




    
    
<script src="https://unpkg.com/locomotive-scroll@4.1.4/dist/locomotive-scroll.min.js"></script>

    
<script src="https://unpkg.com/@fancyapps/ui@4.0/dist/fancybox.umd.js"></script>

    

    
        <script src="/blog/js/plugins/typing.js?v=2.0.0"></script>
    

    

    <!-- 数学公式 -->
    

    <!-- 评论插件 -->
    
        

        
    



<!-- CDN -->


    

    

    




    <!-- Service Worker -->
    
    <!-- baidu push -->
    


<script id="async-script" src="/blog/js/main.js?v=2.0.0"></script>

</body>

</html>